package org.leaf.green.b2b

class DistributionDetail {//配送明细

    Distribution distribution//配送单
    String serialNumber//序号
    Product product//产品
    Package packages//包装
    String unit//单位
    BigDecimal quantity//配送数量
    BigDecimal sended//已发数量
    BigDecimal price//成本价
    BigDecimal retailPrice//零售价
    BigDecimal amount//成本金额
    BigDecimal retailAmount//零售金额
    BigDecimal packageUsed//包装使用数量
    BigDecimal packageReturned//包装归还数量

    static belongsTo = [distribution : Distribution]

    static constraints = {
        distribution(nullable : false)
        serialNumber(nullable:false, blank:false, unique : 'distribution', maxSize : 3)
        product(nullable:false)
        packages(nullalbe:true)
        unit(nullable:false, blank:false, maxSize : 4)
        quantity(nullable:false, scale : 2)
        sended(nullable:false, scale : 2)
        price(nullable:false, scale : 2)
        retailPrice(nullable:false, scale : 2)
        amount(nullable:false, scale : 2)
        retailAmount(nullable:false, scale : 2)
        packageUsed(nullable:false, scale : 2)
        packageReturned(nullable:false, scale : 2, validator : {val, obj ->
            return obj.packageUsed - val >= 0
        })
    }

    String toString(){
        return "$serialNumber"
    }

    static mapping = {
        table 'B2B_DISTRIBUTION_DETAIL'
    }
}
